﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserPermission.aspx.cs" Inherits="Web.AuthorizationSystem.UserPermission" Theme="Default" %>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>用户权限配置</title>
    <script language="javascript" type="text/javascript">
        //JS控制Tree的checkbox关联操作
        function OnTreeNodeChecked() {
            var ele = event.srcElement;
            if (ele.type == 'checkbox') {
                var childrenDivID = ele.id.replace('CheckBox', 'Nodes');
                var div = document.getElementById(childrenDivID);
                if (div != null) {
                    var checkBoxs = div.getElementsByTagName('INPUT');
                    for (var i = 0; i < checkBoxs.length; i++) {
                        if (checkBoxs[i].type == 'checkbox')
                            checkBoxs[i].checked = ele.checked;
                    }
                } else {
                    var div = GetParentByTagName(ele, 'DIV');
                    var checkBoxs = div.getElementsByTagName('INPUT');
                    var parentCheckBoxID = div.id.replace('Nodes', 'CheckBox');
                    var parentCheckBox = document.getElementById(parentCheckBoxID);
                    for (var i = 0; i < checkBoxs.length; i++) {
                        if (checkBoxs[i].type == 'checkbox' && checkBoxs[i].checked) {
                            parentCheckBox.checked = true;
                            return;
                        }
                    }
                    parentCheckBox.checked = false;
                }

            }
        }

        function GetParentByTagName(element, tagName) {
            var parent = element.parentNode;
            var upperTagName = tagName.toUpperCase();
            while (parent && (parent.tagName.toUpperCase() != upperTagName)) {
                parent = parent.parentNode ? parent.parentNode : parent.parentElement;
            }
            return parent;
        }
    </script>
    <style>
        .panel1 {
            float: left;
            width: 40%;
        }
        .panel2 {
            float: left;
            width: 60%;
        }
        #panel3 {
            margin-left: 30px;
            margin-top: 30px;
        }
        .panel3 {
            margin-left: 30px;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="tabletitle1">
            用户权限配置
        </div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Panel ID="Panel1" runat="server" CssClass="panel1">
                    <table>
                        <tr>
                            <td>名字/账号:</td>
                            <td>
                                <dx:ASPxTextBox ID="txtUserName" runat="server" Width="170px"></dx:ASPxTextBox>
                            </td>
                            <td>部门:</td>
                            <td>
                                <dx:ASPxComboBox ID="comboDepartment" runat="server" ValueType="System.String"></dx:ASPxComboBox>
                            </td>
                            <td>
                                <dx:ASPxButton ID="btnSearch" runat="server" Text="查询" OnClick="btnSearch_OnClick"></dx:ASPxButton>
                            </td>
                        </tr>
                    </table>
                    <div style="height: 600px;">
                        <dx:ASPxGridView ID="gridUser" runat="server" KeyFieldName="USERID" AutoGenerateColumns="False" Width="100%" EnableCallBacks="True">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="USERID" Caption="用户ID" Width="15%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="USERNAME" Caption="用户名">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="DEPARTMENTNAME" Caption="部门">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn Width="35px">
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="lnbModify" runat="server" CausesValidation="false" Text="修改"
                                                        CommandArgument='<%#Eval("USERID")%>' OnCommand="lnbModify_OnCommand"></asp:LinkButton>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                            </Columns>
                            <Settings VerticalScrollableHeight="500" VerticalScrollBarMode="Hidden"></Settings>
                        </dx:ASPxGridView>
                    </div>
                </asp:Panel> 
                <asp:Panel ID="Panel2" runat="server" CssClass="panel2">
                    <fieldset style="border: 1px solid  cornflowerblue">
                        <legend style="font-weight: bold">修改权限</legend>
                    <asp:Panel ID="panel3" runat="server" BorderStyle="solid" BorderWidth="1px" BorderColor="black"
                               Width="250px" Height="500px" ScrollBars="Auto">
                        <asp:TreeView id="crTreeViewAllPermission" onclick="OnTreeNodeChecked()" runat="server" CssClass="treeVi" NodeIndent="10" ExpandDepth="0" ShowCheckBoxes="All" ShowLines="true" Enabled="False">
                            <ParentNodeStyle ImageUrl="~/Images/parentfolders.gif" Font-Bold="True" ForeColor="Black"></ParentNodeStyle>

                            <HoverNodeStyle Font-Underline="False"></HoverNodeStyle>

                            <SelectedNodeStyle HorizontalPadding="0px" VerticalPadding="0px" Font-Underline="True"></SelectedNodeStyle>

                            <RootNodeStyle ImageUrl="~/Images/parentfolders.gif"></RootNodeStyle>

                            <NodeStyle HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"></NodeStyle>

                            <LeafNodeStyle ImageUrl="~/Images/sonfolder1.gif"></LeafNodeStyle>
                        </asp:TreeView>
                    </asp:Panel>
                    <div class="panel3">
                        <dx:ASPxButton ID="btnSave" runat="server" Text="保存" OnClick="btnSave_OnClick" Enabled="False"></dx:ASPxButton>
                        <dx:ASPxButton ID="btnCancel" runat="server" Text="取消" OnClick="btnCancel_OnClick" Enabled="False"></dx:ASPxButton>
                    </div>
                    </fieldset>
                </asp:Panel>
                
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
